<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>h5拖放</title>
		<style>
			#div1{
				width: 300px;
				height: 150px;
				padding: 10px;
				border: 1px solid gray;
				
			}
		</style>
	</head>
	<body>
		<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)">
			
		</div>
		<img id="drag1" src="bg.jpg" alt="" width="280" draggable="true" ondragstart="drag(event)">
		<script>
			function allowDrop (ev) {
				ev.preventDefault()
			}
			function drag (ev) {
				console.log(ev);
				ev.dataTransfer.setData("myImg",ev.target.id)
			}
			function drop (ev) {
				ev.preventDefault();
				var data = ev.dataTransfer.getData("myImg")
				ev.target.appendChild(document.getElementById(data))
			}
		</script>
	</body>
</html>